//
//  BGcollectionViews.m
//  bigMall
//
//  Created by LTOVE on 16/9/22.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGcollectionViews.h"

@interface BGcollectionViews ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end
#pragma  collectionCell

@interface collectionViewCells ()
@property (nonatomic,weak)UIImage *dataArray;
@property (nonatomic,retain)UIImageView *imageView;
+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView IndexPath:(NSIndexPath *)indexPath;
@end

//@interface collectionViewCells : UICollectionViewCell
//
//@property (nonatomic,strong)NSArray *dataArray;
//@property (nonatomic,retain)UIImageView *imageView;
//+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView IndexPath:(NSIndexPath *)indexPath;
//
//@end
@implementation BGcollectionViews


- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    [self reloadData];
}

- (instancetype)init
{
//    [super init];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(100, 100);
    layout.scrollDirection = UICollectionViewScrollPositionNone;
    layout.minimumLineSpacing = 3;
    self.delegate = self;
    self.dataSource = self;
//    [self registerClass:[self class] forCellWithReuseIdentifier:@"cell"];
    return [self initWithFrame:CGRectMake(0, 0, screenW, screenW) collectionViewLayout:layout];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count + 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    collectionViewCells *cell = [collectionViewCells cellWithCollectionView:collectionView IndexPath:indexPath];
//    cell.backgroundColor = read_;
    if (self.dataArray.count == indexPath.row) {
        cell.dataArray = [UIImage imageNamed:@"ellipse-2"];
        
    }else{
        NSLog(@"----->%@",self.dataArray);
//        cell.dataArray = [UIImage imageNamed:@"11"];
        cell.dataArray = self.dataArray[indexPath.row];
        }
    return cell;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat WH = (screenW - 20 - 40 ) /3.0;
    return CGSizeMake(WH, WH);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    if (indexPath.row == self.dataArray.count) {
//        if ([_Mydelegate respondsToSelector:@selector(lastItemsCellSelected)]) {
//            [_Mydelegate lastItemsCellSelected];
//        }
//    }
//    
    if ([_Mydelegate respondsToSelector:@selector(lastItemsCellSelected)]) {
        [_Mydelegate lastItemsCellSelected];
    }
}
@end

//#pragma  collectionCell
//@interface collectionViewCells : UICollectionViewCell
//
//@property (nonatomic,strong)NSArray *dataArray;
//
//+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView IndexPath:(NSIndexPath *)indexPath;
//
//@end


#pragma 实现
static NSString *const reuseIdentify = @"cell";
//static UICollectionView *_collectionView = nil;
@implementation collectionViewCells

- (UIImageView *)imageView
{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        [self addSubview:_imageView];
    }
    return _imageView;
}

- (void)setDataArray:(UIImage *)dataArray
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.bounds];
////    _imageView.size = CGSizeMake(100, 100);
//    _imageView.backgroundColor = lightwhite_;
//    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"6"]];
    imageView.backgroundColor = read_;
    CGSize size = self.size;
    NSLog(@"%f",size.height);
    
    imageView.image = dataArray;
//    [_imageView setImage:[UIImage imageNamed:@"--销售"]];
    [self.contentView addSubview:imageView];
    
}
+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView IndexPath:(NSIndexPath *)indexPath
{
//    if (!_collectionView) {
//        _collectionView = collectionView;
//        [collectionView registerClass:[collectionViewCells class] forCellWithReuseIdentifier:reuseIdentify];
//    }
    return [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentify forIndexPath:indexPath];
}



@end